package cn.pzhu.java.ch03.polymorphism;
class A{
	void foo(){
		System.out.println("A foo");
	}
}
class B1 extends A{
	void foo(){
		System.out.println("B1 foo");
	}
}
class B2 extends A{
	void foo(){
		System.out.println("B2 foo");
	}
}
class C1 extends B1{
	void foo(){
		System.out.println("C1 foo");
	}
}
public class PlyDemo {
	public static void main(String[] args) {
//		A objs[]={
//			new A(),new B1(),new B2(),new C1()
//		};
		
		A a1=new A();
		A a2=new B1();  // B1 b1=new B1(); A a2=b1;
		A a3=new B2();
		A a4=new C1();  // C1 c1=new C1();B1 b1=c1; A a4=b1;
		A objs[]={a1,a2,a3,a4};
		
		for(A a:objs){
			a.foo();  //A foo,B1 foo
					  //B2.foo C1 foo
		}
	}

}
